﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;

namespace Shakes_and_Fidget_Charplaner
{
    public class NumTextBox : TextBox
    {
        // Zusammenfassung:
        //     Gets or sets a value indicating whether the use of comma in a NumTextBox
        //     is allowed.
        //
        // Rückgabewerte:
        //     true if the NumTextBox should accept commas,
        //     otherwise false
        [DefaultValue(false)]
        public bool AllowComma { get; set; }
        public ToolTip capslock = new ToolTip();


        protected override void OnEnter(EventArgs e)
        {
            capslock.ToolTipIcon = ToolTipIcon.Warning;
            //capslock.AutoPopDelay = 100000;
            capslock.ToolTipTitle = "Feststelltaste";
            if (Console.CapsLock)
                capslock.Show("Die Feststelltaste ist aktiviert!", Parent, this.Location.X + this.Size.Width, this.Location.Y);
            else
                capslock.Hide(this);
            base.OnEnter(e);
        }
        protected override void OnLeave(EventArgs e)
        {
            capslock.Hide(this);
            base.OnLeave(e);
        }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            capslock.ToolTipIcon = ToolTipIcon.Warning;
            //capslock.AutoPopDelay = 100000;
            capslock.ToolTipTitle = "Feststelltaste";
            if (Console.CapsLock)
                capslock.Show("Die Feststelltaste ist aktiviert!", Parent, this.Location.X + this.Size.Width, this.Location.Y);
            else
                capslock.Hide(this);
            base.OnKeyDown(e);
        }
        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            capslock.ToolTipIcon = ToolTipIcon.Warning;
            //capslock.AutoPopDelay = 100000;
            capslock.ToolTipTitle = "Feststelltaste";
            if (Console.CapsLock)
                capslock.Show("Die Feststelltaste ist aktiviert!", Parent, this.Location.X + this.Size.Width, this.Location.Y);
            else
                capslock.Hide(this);
            if (!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar) && e.KeyChar != ',')
                e.Handled = true;
            if (this.Text.Contains(',') && e.KeyChar == ',')
                e.Handled = true;
            if (e.KeyChar == ',' && this.Text == "")
                e.Handled = true;
            if (!AllowComma && e.KeyChar == ',')
                e.Handled = true;
            base.OnKeyPress(e);
        }
    }
}
